package com.slipper.bpmn.dealer;

import java.util.HashMap;
import java.util.Map;

public class NodeDealerFactory {
    private static final Map<String, INodeDealer> nodeDealerMap = new HashMap<>();
    
    public static void register(String[] types, INodeDealer nodeDealer) {
        if (types == null || types.length == 0) {
            throw new RuntimeException("注册节点处理器的节点类型不能为空！");
        }
        
        for (String type : types) {
            if (nodeDealerMap.containsKey(type)) {
                throw new RuntimeException("节点类型为[" + type + "]的节点处理器重复注册！");
            }
            nodeDealerMap.put(type, nodeDealer);
        }
    }
    
    public static INodeDealer getNodeDealer(String type) {
        INodeDealer nodeDealer = nodeDealerMap.get(type);
        if (nodeDealer == null) {
            throw new RuntimeException("节点类型为[" + type + "]的节点处理器不存在！");
        }
        return nodeDealer;
    }
}
